<%@ Page Language="C#" MasterPageFile="~/SurveyHost.Master" AutoEventWireup="true"
    CodeBehind="Questions.aspx.cs" Inherits="SurveyHost.Web.Admin.Questions" MaintainScrollPositionOnPostback="true"
    Title="Edit Questions" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="post">
        <h1 class="title">
            edit questions
        </h1>
        <p class="byline">
            Add, edit and delete Questions here
        </p>
        <div class="entry">
            <asp:FormView ID="FormView1" runat="server" DataSourceID="StemDetailDataSource" Width="100%"
                OnItemInserting="FormView1_ItemInserting" 
                OnDataBound="FormView1_DataBound" OnItemDeleted="FormView1_ItemDeleted"
                OnItemInserted="FormView1_ItemInserted" 
                OnItemUpdated="FormView1_ItemUpdated" DataKeyNames="StemId">
                <InsertItemTemplate>
                    <div style="width: 50%; float: left;">
                        <span class="Underscore"><a href="Measures.aspx">measure</a> name:</span><br />
                        <asp:DropDownList ID="MeasureNameDropdown" runat="server" DataSourceID="MeasureDataSource"
                            DataTextField="MeasureName" DataValueField="MeasureName" SelectedValue='<%#Bind("MeasureName")%>'
                            ToolTip="Questions are organized into measures">
                        </asp:DropDownList>
                    </div>
                    <div style="width: 50%; float: right;">
                        <span class="Underscore">Rank:</span>&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
                            ControlToValidate="RankTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Must be between 1 and 1000"
                            Type="integer" MinimumValue="1" MaximumValue="1000" ControlToValidate="RankTextBox"
                            Display="dynamic"></asp:RangeValidator><br />
                        <asp:TextBox ID="RankTextBox" runat="server" Text='<%# Bind("Rank") %>' Columns="3"
                            Rows="1" MaxLength="4" ToolTip="Questions are ordered by measure rank, then by question rank">
                        </asp:TextBox></div>
                    <div style="clear: both;">
                        <span class="Underscore">Question text:</span>&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required"
                            ControlToValidate="QuestionTextTextBox"></asp:RequiredFieldValidator><br />
                        <asp:TextBox ID="QuestionTextTextBox" runat="server" Text='<%# Bind("QuestionText") %>'
                            Rows="3" Width="100%" TextMode="MultiLine" Wrap="true" ToolTip="Html is not allowed">
                        </asp:TextBox><br />
                        <span class="Underscore">Answer Type:</span><br />
                        <asp:DropDownList ID="AnswerTypeDropdown" runat="server" 
                            DataSourceID="AnswerTypeDataSource" AutoPostBack="true"
                            DataTextField="AnswerTypeName" DataValueField="AnswerTypeName" 
                            SelectedValue='<%#Bind("AnswerTypeName")%>' 
                            onselectedindexchanged="AnswerTypeDropdown_SelectedIndexChanged">
                        </asp:DropDownList>
                        <br />
                        <span class="Underscore">Answer configuration:</span><br />
                        <asp:Label ID="HelpText" runat="server"></asp:Label>
                        <asp:TextBox ID="AnswerConfiguration" runat="server" Text='<%# Bind("AnswerTypeConfiguration") %>'
                            Rows="2" Width="100%" TextMode="MultiLine" Wrap="true">
                        </asp:TextBox>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                            Text="Insert"></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel"></asp:LinkButton></div>
                </InsertItemTemplate>
                <EditItemTemplate>
                    <div style="width: 50%; float: left;">
                        <span class="Underscore"><a href="Measures.aspx">measure</a> name:</span><br />
                        <asp:DropDownList ID="MeasureNameDropdown" runat="server" DataSourceID="MeasureDataSource"
                            DataTextField="MeasureName" DataValueField="MeasureName" SelectedValue='<%#Bind("MeasureName")%>'
                            ToolTip="Questions are organized into measures">
                        </asp:DropDownList>
                    </div>
                    <div style="width: 50%; float: right;">
                        <span class="Underscore">Rank:</span>&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
                            ControlToValidate="RankTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Must be between 1 and 1000"
                            Type="integer" MinimumValue="1" MaximumValue="1000" ControlToValidate="RankTextBox"
                            Display="dynamic"></asp:RangeValidator>
                        <asp:TextBox ID="RankTextBox" runat="server" Text='<%# Bind("Rank") %>' Columns="3"
                            Rows="1" MaxLength="4" ToolTip="Questions are ordered by measure rank, then by question rank">
                        </asp:TextBox></div>
                    <div style="clear: both;">
                        <span class="Underscore">Question text:</span>&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required"
                            ControlToValidate="QuestionTextTextBox"></asp:RequiredFieldValidator><br />
                        <asp:TextBox ID="QuestionTextTextBox" runat="server" Text='<%# Bind("QuestionText") %>'
                            Rows="3" Width="100%" TextMode="MultiLine" Wrap="true" ToolTip="Html is not allowed">
                        </asp:TextBox><br />
                        <span class="Underscore">Answer Type:</span><br />
                        <asp:DropDownList ID="AnswerTypeDropdown" runat="server" DataSourceID="AnswerTypeDataSource"
                            DataTextField="AnswerTypeName" DataValueField="AnswerTypeName" 
                            SelectedValue='<%#Bind("AnswerTypeName")%>' AutoPostBack="True" 
                            onselectedindexchanged="AnswerTypeDropdown_SelectedIndexChanged">
                        </asp:DropDownList>
                        <br />
                        <span class="Underscore">Answer configuration:</span><br />
                        <asp:Label ID="HelpText" runat="server"></asp:Label>
                        <asp:TextBox ID="AnswerConfiguration" runat="server" Text='<%# Bind("AnswerTypeConfiguration") %>'
                            Rows="2" Width="100%" TextMode="MultiLine" Wrap="true">
                        </asp:TextBox>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                            Text="Update"></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                            Text="Cancel"></asp:LinkButton></div>
                </EditItemTemplate>
                <ItemTemplate>
                    <div style="width: 50%; float: left;">
                        <span class="Underscore"><a href="Measures.aspx">Measure</a> name:</span>&nbsp;&nbsp;<br />
                        <asp:Label ID="MeasureNameLabel" runat="server" Text='<%# Bind("MeasureName") %>'></asp:Label>
                    </div>
                    <div style="width: 50%; float: right;">
                        <span class="Underscore">Rank:</span>&nbsp;&nbsp;
                        <asp:Label ID="RankLabel" runat="server" Text='<%# Bind("Rank") %>'></asp:Label>
                    </div>
                    <div style="clear: both;">
                        <p>
                            <span class="Underscore">Question text:</span><br />
                            <asp:Label ID="QuestionTextLabel" runat="server" Text='<%# Bind("QuestionText") %>'></asp:Label></p>
                        <span class="Underscore">Answer type:</span><br />
                        <asp:Label ID="AnswerTypeNameLabel" runat="server" Text='<%# Bind("AnswerTypeName") %>'></asp:Label>
                        <p>
                            <span class="Underscore">Answer type configuration:</span><br />
                            <asp:Label ID="AnswerTypeConfigurationLabel" runat="server" Text='<%# Bind("AnswerTypeConfiguration") %>'></asp:Label></p>
                    </div>
                    <div style="text-align: right;">
                        <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                            Text="Edit"></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                            Text="Delete"></asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                            Text="New"></asp:LinkButton></div>
                </ItemTemplate>
                <EmptyDataTemplate>
                    <p>
                        To view the details of a Question, click the &quot;Select&quot; link of the Question you 
                        wish to inspect in the grid below.</p>
                    <p>
                        To edit a Question, select it and then click the &quot;Edit&quot; link that appears in 
                        this section.</p>
                    <p>
                        To delete a Question, select it in the grid below and then click the &quot;Delete&quot; 
                        link that appears in this section.</p>
                    <p>
                        <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                            Text="To create a new Question, click here.">
                        </asp:LinkButton></p>
                </EmptyDataTemplate>
            </asp:FormView>
        </div>
    </div>
    <div class="post">
        <h1 class="title">
            questions         </h1>
        <p class="byline">
            Select a Question to edit or delete it
        </p>
        <div class="entry">
            <asp:GridView ID="GridView1" runat="server" CellPadding="3" AutoGenerateColumns="False"
                BorderStyle="None" AllowPaging="True" AllowSorting="True" DataSourceID="StemDataSource"
                GridLines="None" Width="100%" OnRowUpdating="GridView1_RowUpdating" OnRowDeleted="GridView1_RowDeleted"
                DataKeyNames="StemId" PageSize="50">
                <RowStyle CssClass="gridRowStyle" BackColor="#EEEEEE" ForeColor="Black" />
                <AlternatingRowStyle CssClass="gridAlternatingRowStyle" BackColor="Gainsboro" />
                <PagerStyle CssClass="gridPagerStyle" BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                <HeaderStyle CssClass="callOutStyle" Font-Bold="True" BackColor="#CCCCCC" ForeColor="Black"
                    HorizontalAlign="Left" />
                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                <SelectedRowStyle CssClass="gridSelectedRowStyle" BackColor="#008A8C" Font-Bold="True"
                    ForeColor="White" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" >
                        <HeaderStyle Width="3em" />
                    </asp:CommandField>
                    <asp:BoundField DataField="MeasureName" HeaderText="Measure" 
                        SortExpression="MeasureName" >
                        <HeaderStyle Width="60px" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Rank" HeaderText="Rank" SortExpression="Rank" >
                        <HeaderStyle Width="2em" />
                    </asp:BoundField>
                    <asp:BoundField DataField="QuestionText" HeaderText="Question Text" 
                        SortExpression="QuestionText" HtmlEncode="False" 
                        HtmlEncodeFormatString="False" />
                </Columns>
            </asp:GridView>
            <asp:Label ID="ResultText" runat="server" EnableViewState="False"></asp:Label>
        </div>
    </div>
    <asp:ObjectDataSource ID="AnswerTypeDataSource" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
        TypeName="SurveyHost.Core.DAL.AnswerObjectTypeController">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="StemDetailDataSource" runat="server" DeleteMethod="Delete"
        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="FetchByID"
        TypeName="SurveyHost.Core.DAL.StemController" UpdateMethod="Update">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="StemId" PropertyName="SelectedValue"
                Type="Object" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="StemId" Type="Object" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter DbType="Object" Name="StemId" />
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="QuestionText" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="AnswerTypeName" Type="String" />
            <asp:Parameter Name="AnswerTypeConfiguration" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter DbType="Object" Name="StemId" />
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="QuestionText" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="AnswerTypeName" Type="String" />
            <asp:Parameter Name="AnswerTypeConfiguration" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="MeasureDataSource" runat="server" DeleteMethod="Destroy"
        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
        TypeName="SurveyHost.Core.DAL.MeasureController" UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="MeasureName" Type="Object" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="DefaultAnswerTypeName" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="DefaultAnswerTypeName" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="StemDataSource" runat="server" DeleteMethod="Destroy" InsertMethod="Insert"
        SelectMethod="FetchAll" 
        TypeName="SurveyHost.Core.DAL.StemController" UpdateMethod="Update" 
        OldValuesParameterFormatString="original_{0}">
        <DeleteParameters>
            <asp:Parameter Name="StemId" Type="Object" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="StemId" Type="Object" />
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="QuestionText" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="AnswerTypeName" Type="String" />
            <asp:Parameter Name="AnswerTypeConfiguration" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="StemId" Type="Object" />
            <asp:Parameter Name="MeasureName" Type="String" />
            <asp:Parameter Name="QuestionText" Type="String" />
            <asp:Parameter Name="Rank" Type="Int32" />
            <asp:Parameter Name="AnswerTypeName" Type="String" />
            <asp:Parameter Name="AnswerTypeConfiguration" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
</asp:Content>